import {ref} from 'vue';
import {SparePartTypeListItem} from '../types';
import apiParts from '@/util/network_api/parts.js';

/**
 * 物料分类列表服务
 */
export default function () {
	const sparePartTypeList = ref<Array<SparePartTypeListItem>>([]);

	const getSparePartTypeList = async () => {
		try {
			const res = await apiParts.getSpareContactGoodTypeList();
			if (res.code === 20000) {
				sparePartTypeList.value = res.data.rows
				return ''
			}
			
			return res.message
		} catch (e) {
			return '获取分类列表失败，请稍后重试'
		}
	};

	return {
		sparePartTypeList,
		getSparePartTypeList,
	};
}
